@extends('layouts.head')

@section('content')
<section class="content-header" id="content-header">
商品信息

</section>

<section class="content" id="content">
<div class="box box-solid" >
  <div class="box-header with-border">
    <el-button-group>
          <el-button @click="addGoodsV = true " type="primary"  size="small" >添加</el-button>
          <el-button @click="getNew"   size="small" >刷新</el-button>
          <el-button  @click="editRow()"  :disabled="!isCheckOne"  size="small">编辑</el-button>
          <el-button  @click="outRow()"  :disabled="!isCheckOne" type="primary"  size="small">转出</el-button>
          <el-button  @click="finishRow()"  type="primary"   size="small">完成</el-button>
          <el-button  @click="delRow()" type="danger" size="small">删除</el-button>
    </el-button-group> 
    <el-button size="small" type=""  @click="yesterday" icon="arrow-left"></el-button>
    <el-date-picker v-model="date" style="width: 120px" size="small" type="date" placeholder="选择日期" > </el-date-picker>
    <el-button  size="small" type="" @click="tomorrow"  icon="arrow-right" ></el-button>
    <button class="mdui-btn btn-info mdui-btn-dense mdui-btn-raised " @click="getNew" >新商品</button>
    <button class="mdui-btn btn-info mdui-btn-dense mdui-btn-raised " @click="getAlloted" >已分配</button>
    <button class="mdui-btn btn-info mdui-btn-dense mdui-btn-raised " @click="getWorking" >已开工</button>
    <button class="mdui-btn btn-info mdui-btn-dense mdui-btn-raised " @click="getStorage" >已入库</button>
    <button class="mdui-btn btn-info mdui-btn-dense mdui-btn-raised " @click="getFinish" >已完成</button>

</el-input>
  </div>
  <div class="box-body " >
         <el-table ref="multipleTable" :data="goods" border bordertooltip-effect="dark" border="true"  highlight-current-row
    @current-change="lookRow"   @selection-change="checkOne" style="width: 100%;font-size: xx-small;" >
            <el-table-column type="selection" width="40">  </el-table-column>
            <el-table-column  fixed="left" type="index" width="40" > </el-table-column>
            <el-table-column  fixed="left" label="品名" prop="name"  width="160"> </el-table-column>
            <el-table-column   label="品号" prop="code" width="160"> </el-table-column>
            <el-table-column  prop="type" label="规格" > </el-table-column>
            <el-table-column  prop="unit" label="单位" >  </el-table-column>
            <el-table-column  prop="weight" label="重量（g）" > </el-table-column>
            <el-table-column  prop="cost" label="价钱" > </el-table-column>
<!--             <el-table-column fixed="right"  label="操作"  width="120">
                <template scope="scope">
                  <el-button-group>
                     
                      <el-button  @click="editRow(scope.row.id, goods)" type="primary" icon=" " size="mini">编辑</el-button>
                      <el-button  @click="delRow(scope.row.id, goods)" type="danger" icon=" " size="mini">删除</el-button>
                  </el-button-group>     
                </template>
            </el-table-column> -->
        </el-table>
        </br>
        <div class="block">
            <el-pagination @size-change=""  @current-change="getgoodsCurrentPage" :current-page="goodsCurrentPage" :page-size="15" layout="total, prev, pager, next, jumper" :total="goodsCount">
            </el-pagination>
        </div>
  </div>
</div>


<el-dialog title="添加商品" :visible.sync="addGoodsV"   >
<el-form ref="form" :model="addGoodsItem" label-width="80px">
  <el-form-item label="商品名">
    <el-input v-model="addGoodsItem.goodsNo" size="small" ></el-input>
  </el-form-item>
  <el-form-item label="url">
    <el-input v-model="addGoodsItem.goodsDate"  size="small" ></el-input>
  </el-form-item>
  <el-form-item label="优先级">
      <el-input v-model="addGoodsItem.goodsName"  size="small" ></el-input>
  </el-form-item>
  <el-form-item label="图标">
      <el-input v-model="addGoodsItem.goodsCode"  size="small" ></el-input>
  </el-form-item>
  <el-form-item label="父级">
      <select  class="form-control" v-model="addGoodsItem.pid">
      <option v-bind:value="0">  无 </option>
        <option v-for="option in goods" v-bind:value="option.id">
          @{{ option.name }}
        </option>
      </select>
  </el-form-item>
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addGoodsV = false">取 消</el-button>
    <el-button type="primary" @click="submitAddGoods">确 定 </el-button>
  </span>
</el-dialog>


<el-dialog title="修改商品" :visible.sync="editGoodsV"   >
  <el-form ref="form" :model="editGoodsItem" label-width="80px">
    <el-form-item label="商品名">
    <el-input v-model="editGoodsItem.goodsNo" size="small" ></el-input>
  </el-form-item>
  <el-form-item label="goodsDate">
    <el-input v-model="editGoodsItem.goodsDate"  size="small"   ></el-input>
  </el-form-item>
  <el-form-item label="优先级">
      <el-input v-model="editGoodsItem.goodsName"  size="small" ></el-input>
  </el-form-item>
  <el-form-item label="图标">
      <el-input v-model="editGoodsItem.goodsCode"  size="small" ></el-input>
  </el-form-item>
  <el-form-item label="父级"   v-if="editGoodsItem.url == 'parent' " >
       <el-input  :disabled="true" ></el-input>
  </el-form-item>
  <el-form-item label="父级"   v-else >
      <select  class="form-control" v-model="editGoodsItem.pid">
      <option v-bind:value="0">  无 </option>
        <option v-for="option in goods" v-bind:value="option.id">
          @{{ option.name }}
        </option>
      </select>
  </el-form-item>
  
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="editGoodsV = false">取 消</el-button>
    <el-button type="primary" @click="submitEditGoods">确 定 </el-button>
  </span>
</el-dialog>



</section>
<script >
    var content =new Vue({
        el:'#content',
        data:{
            date:'<?php echo date('Y-m-d') ?>',
            addGoodsV:false,
            editGoodsV:false,
            goods:[],
            goodsChrildren:[],
            goodsCount:1,
            goodsCurrentPage:1,
            type:0,
            addGoodsItem:{_token:'',name:'',url:'',pid:0,rank:0,listRank:99,ico:'',state:0,},
            editGoodsItem:{_token:'',},
            multipleSelection: [],
        },
        created:function(){
            this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
            this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

        },
        computed: {
              isCheckOne:function(){
                if( this.multipleSelection.length == 1 ){
                  return true;
                }else{
                  return false;
                }
              }
        },
        methods:{
              getNew:function(){
                 this.type=0;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              getAlloted:function(){
                this.type=1;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              getWorking:function(){
                 this.type=2;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              getStorage:function(){
                 this.type=3;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              getFinish:function(){
                 this.type=4;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                  this.$http.get('/rules/getAll').then((response) => {this.rules=response.data; console.log('rules,success')},(response) =>{ });

              },
              search:function(){
                  console.log(this.searchWord);
                  this.$http.get('/goods/search/'+this.searchWord).then((response) => {this.goods=response.data; this.goodsCount = this.goods.length;console.log('word,goods,success')},(response) =>{ console.log(response);}); 
                  
              } ,
              yesterday:function(){
                  console.log('yesterday');
              },
              tomorrow:function(){
                  console.log('tomorrow');
              },
              submitAddGoods:function(){
                  console.log('submitAddGoods');
                  this.addGoodsV = false;
                  this.addGoodsItem._token = '{{csrf_token()}}';
                  this.$http.post('/goods/add',this.addGoodsItem).then((response)=>{this.$notify.success('添加成功');
                              this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                              this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                        },(response) =>{ this.$notify.error('未知错误')});

              },
              submitEditGoods:function(){
                  console.log('submitEditGoods');
                  this.editGoodsV = false;
                  this.editGoodsItem._token = '{{csrf_token()}}';
                  this.$http.post('/goods/update/'+this.editGoodsItem.id,this.editGoodsItem).then((response)=>{this.$notify.info(response.data);
                              this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                              this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });        

                        },(response) =>{ });
              },
              cancelAddGoods:function(){
                  console.log('cancelAddGoods');
              },
              lookRow:function(val){
                  console.log(val);
              },
              editRow:function(){
                 this.editGoodsV=true;
                 this.editGoodsItem=this.multipleSelection[0]
                  console.log(this.editGoodsItem);
              },
              delRow:function(val){
                  console.log(val);
                  this.$http.post('/goods/del',{_token:'{{csrf_token()}}',date:this.multipleSelection}).then((response) => {this.$notify.info(response.data);
                                this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                                this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       

                          },(response) =>{ }); 

              },
              getgoodsCurrentPage:function(val){
                  console.log(val);
                  this.goodsCurrentPage=val;
                  this.$http.get('/goods/getCurrent/'+this.goodsCurrentPage+'/'+this.type).then((response) => {this.goods=response.data; console.log(response.data)},(response) =>{ }); 
                  this.$http.get('/goods/getCount/'+this.type).then((response) => {this.goodsCount=response.data; console.log(response.data)},(response) =>{ });       
              },
            
              checkChange:function(rows){
                     if (rows) {
                        rows.forEach(row => {
                          this.$refs.multipleTable.toggleRowSelection(row);
                        });
                      } else {
                        this.$refs.multipleTable.clearSelection();
                      }
              }, 
              checkOne:function (val) {
                console.log('11');
                console.log(val);
                this.multipleSelection = val;
              } ,
         },

  });
</script>




@endsection

@section('pagejs')

@endsection

        




